package com.plum.admin.common.strategy.data;

import com.plum.admin.common.enums.DataScopeTypeEnum;
import com.plum.admin.modules.sys.dto.RoleDTO;
import com.plum.admin.modules.sys.service.ISysDeptService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * TODO
 *
 * @author 子丶沫
 * @version 1.0
 * @date 2021/9/1 17:01
 */
@Component("4")
@RequiredArgsConstructor
public class CustomDataScope implements AbstractDataScopeHandler {
    private final ISysDeptService deptService;
    @Override
    public List<String> getDeptIdList(RoleDTO roleDTO, DataScopeTypeEnum scopeTypeEnum) {
        List<String> deptIdList = roleDTO.getDeptIdList();
        List<String> deptIds=new ArrayList<>();
        for (String deptId : deptIdList) {
            deptIds.addAll(deptService.queryDeptIds(deptId));
        }
        Set<String> set=new HashSet<>(deptIds);
        deptIds.clear();
        deptIds.addAll(set);
        return deptIds;
    }
}
